﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;

using System.Net.Mail;

public partial class f_pass : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = null;

        con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        con.Open();


        SqlCommand cmd = new SqlCommand("SELECT * FROM admin1 where username='" + TextBox1.Text + "'", con);

        SqlDataReader dr = cmd.ExecuteReader();
        // Response.Write(@"<script language='javascript'>alert('loop 1')</script>");

        if (dr.Read())
        {
            
            if (TextBox1.Text.Equals(dr[0].ToString()))
            {
                Session["email"] = TextBox1.Text;
                string pass = dr[1].ToString();
                
                    
                    MailMessage mail = new MailMessage();
                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                    mail.From = new MailAddress("realstate777@gmail.com");
                    mail.To.Add(TextBox1.Text);
                    mail.Subject = "Real state agent account information ";
                    mail.Body = "your password is:-" + pass + "";
                    SmtpServer.Port = 25;
                    SmtpServer.Credentials = new System.Net.NetworkCredential("realstate777@gmail.com", "realstate");
                    SmtpServer.EnableSsl = true;
                    SmtpServer.Send(mail);
                    //Label4.Text = ("Mail Sent Successfull");

              
            

                
                dr.Close();
            }
        }

     

    }
}